package com.sf.fy.uav.applet.third.party.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.sf.fy.uav.applet.third.party.service.ThirdPartyService;
import com.sf.fy.uav.common.response.operational.SelectTerminalListResponse;
import com.sf.fy.uav.task.rest.IntraCityRest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * @author 01430312
 */
@Service
public class ThirdPartyServiceImpl implements ThirdPartyService {

    @Autowired
    private IntraCityRest intraCityRest;

    @Override
    public List<SelectTerminalListResponse> selectTerminalList() {
        List<SelectTerminalListResponse> selectTerminalListResponses = new ArrayList<>();
        JSONObject jsonObject = intraCityRest.selectTerminalList();
        ArrayList arrayList = (ArrayList) jsonObject.get("obj");
        arrayList.forEach(o -> {
            String code = (String) ((LinkedHashMap) o).get("code");
            String address = (String) ((LinkedHashMap) o).get("address");
            String cityName = (String) ((LinkedHashMap) o).get("cityName");
            Integer maxServiceRadius = (Integer) ((LinkedHashMap) o).get("maxServiceRadius");
            String areaName = (String) ((LinkedHashMap) o).get("areaName");
            String latitude = (String) ((LinkedHashMap) o).get("latitude");
            String name = (String) ((LinkedHashMap) o).get("name");
            String connId = (String) ((LinkedHashMap) o).get("connId");
            String provinceName = (String) ((LinkedHashMap) o).get("provinceName");
            String longitude = (String) ((LinkedHashMap) o).get("longitude");
            SelectTerminalListResponse selectTerminalListResponse = new SelectTerminalListResponse();
            selectTerminalListResponse.setAddress(address);
            selectTerminalListResponse.setAreaName(areaName);
            selectTerminalListResponse.setCityName(cityName);
            selectTerminalListResponse.setCode(code);
            selectTerminalListResponse.setConnId(connId);
            selectTerminalListResponse.setLatitude(latitude);
            selectTerminalListResponse.setName(name);
            selectTerminalListResponse.setLongitude(longitude);
            selectTerminalListResponse.setMaxServiceRadius(maxServiceRadius);
            selectTerminalListResponse.setProvinceName(provinceName);
            selectTerminalListResponses.add(selectTerminalListResponse);
        });
        return selectTerminalListResponses;
    }
}
